<?php

namespace web\common\model\user;

/**
 *登录账户信息
 */
class AgentAccount extends \web\common\model\Model {

    protected function _initialize() {
        $this->tableName = 'agant_user_account';
    }

    /**
     *  获取数据详情。
     * @param type $company_id
     * @param type $id
     * @return type
     */
    public function getAccountDetail( $id) {
        $where = array('id' => $id);
        return $this->where($where)->find();
    }
    
   

    /**
     * 逻辑删除。
     * @param type $id
     * @return type
     */
    public function deleteLogicAccount( $id) {
        $where = array('id' => $id);
        $data = array('logic_delete' => 1, 'delete_time' => getTime());
        return $this->save($data, $where);
    }

    /**
     * 根据ID获取数据。 
     * @param type $id
     * @return type
     */
    public function getDataByID($id) {
        return $this->where(array('id' => $id))->find();
    }

    /**
     * 获取密码
     * @param type $id
     * @return type
     */
    public function getPassword($id) {
        $result = $this->field('password')->where(array('id' => $id))->find();
        return $result['password'];
    }

    /**
     * 更新密码
     * @param type $id
     * @param type $password
     * @return type
     */
    public function updatePassword($id, $password) {
        $data = array('password' => md5($password));
        return $this->save($data, array('id' => $id));
    }
    
    /**
     * 根据账号和密码获取用户数据
     * @param type $username
     * @param type $password
     * @return type
     */
    public function getLoginData($username, $password) {
        $sql = 'select id,store_id,username,logic_delete from ' . $this->getTableName().' where username=\'' . $username . '\' and password=\'' . md5($password) . '\'';
        $result = $this->query($sql);
        if (!empty($result) && count($result) > 0)
            return $result[0];
        else
            return null;
    }
    
    

}